import { Button, Space } from 'antd';
import { useHistory, useModel, useAccess, Access } from 'umi';

const Index = () => {
  const history = useHistory();
  const { initialState, loading, error, refresh, setInitialState } =
    useModel('@@initialState');
  const { user, singin, singout } = useModel('user');

  const access = useAccess(); //access实例的成员：canReadFoo，canUpdateFoo，canDeleteFoo
  return (
    <>
      {initialState?.id}
      <br />
      {initialState?.name}
      <br />
      {user?.id}
      {user?.name}
      <br />
      <Space>
        <Access
          accessible={access.isAdmin !== undefined && access.isAdmin}
          fallback={<>没有权限</>}
        >
          <Button type="primary"> test</Button>
        </Access>
        <Button
          type="primary"
          onClick={() => {
            singin('最爱白菜', 123456);
          }}
        >
          登录
        </Button>
        <Button
          type="primary"
          onClick={() => {
            singout();
          }}
        >
          登出
        </Button>
      </Space>
      <br />
      <Button
        onClick={() => {
          history.push('/userinfo');
        }}
      >
        go to UserInfo
      </Button>
      USER INDEX
    </>
  );
};

export default Index;
